﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FanPages.Server.Services.Contracts;
using FanPages.Server.Services.Contracts.Dto;
using FanPages.Server.Repostory.EFRepository.Model;
using FanPages.Common.DataAccess;
using FanPages.Server.Services.Transformers;
using FanPages.Common.Exceptions;

namespace FanPages.Server.Services
{
    public class NewsService : INewsService
    {
        IRepository<SearchResult> repository = new EFRepository<SearchResult>(new FanPagesEntities());

        public List<SearchResultDto> GetByFanItem(Contracts.Dto.FanItemDto fanItem)
        {
            List<SearchResultDto> list = null;
            try
            {
                var news = repository.Find(x => x.FanItem.Id == fanItem.Id).ToList();
                if (news != null)
                {
                    list = new SearchResultTransformerSvc().ToListDto(news);
                }
            }
            catch (Exception ex)
            {
                throw new ServiceException("NewsService.GetByFanItem exception", ex);
            }
            return list;
        }
    }
}
